package ms.jasim.model.editor.actions;

import java.util.List;

import ms.jasim.framework.EventSimulator;
import ms.jasim.model.editor.views.EventSimulationView;
import ms.util.SimulationUtils;
import ms.utils.PerformanceTimer;

import org.eclipse.jface.action.IAction;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;

/**
 * Our sample action implements workbench action delegate.
 * The action proxy will be created by the workbench and
 * shown in the UI. When the user tries to use the action,
 * this delegate will be created and execution will be 
 * delegated to it.
 * @see IWorkbenchWindowActionDelegate
 */
public class SimulateSolutionWithEventAction extends SimulateSolutionAction {

	/**
	 * The action has been activated. The argument of the
	 * method represents the 'real' action sitting
	 * in the workbench UI.
	 * @see IWorkbenchWindowActionDelegate#run
	 */
	@Override
	public void run(IAction action) {
		PerformanceTimer.createEntry("EVENT-SIMUL", "Simulate solution(s) with events");
		List<EventSimulator> result = SimulationUtils.simulateSolutionsWithEvent(null, solutions);
		if (result != null) {
			EventSimulationView view =  (EventSimulationView) SimulationUtils.showView(EventSimulationView.ID);
			if (view != null)
				view.setInput(result);
		}
		PerformanceTimer.closeEntry();
		PerformanceTimer.dumpEntries();
	}

	@Override
	protected void updateActionText(IAction action) {
		if (solutions.size() == 1)
			action.setText("Simulate " + solutions.get(0).getName() + " with EventSet");
		else
			action.setText("Simulate with EventSet");
	}
}